package work.huangxin.share.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import work.huangxin.share.handlerInterceptor.MyInterceptor;

import java.util.List;


/**
 * 拦截器配置拦截路径
 */

@Configuration
public class FilterConfig implements WebMvcConfigurer {

    @Bean
    public MyInterceptor getMyInterceptor() {
        return new MyInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截器拦截请求配置
        registry.addInterceptor(getMyInterceptor())
                .addPathPatterns("/wx/**")
                .excludePathPatterns("/wx/Login")
                .excludePathPatterns("/wx/api/**")
                .excludePathPatterns("/wx/admin/api/loginAdmin")
                .excludePathPatterns("/wx/chat")
                .excludePathPatterns("/wx/manhe/**")
                .excludePathPatterns("/wx/manhe/uploadImage");
//                .excludePathPatterns("/wx/sechandGoods/getPhoto");


//        registry.addInterceptor(MyInterceptor()).addPathPatterns("/api/**").excludePathPatterns("/api/login");

    }

    /**
     * content/jepg格式转换器
     * @param converters
     */

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        WebMvcConfigurer.super.configureMessageConverters(converters);
        work.huangxin.share.config.HttpMessageConverter httpMessageConverter = new work.huangxin.share.config.HttpMessageConverter();
        converters.add(httpMessageConverter);
    }
    //    @Bean
//    public FilterRegistrationBean jwtFilter() {
//        final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
//        registrationBean.setFilter(new JwtFilter());
//        //添加需要拦截的url
//        List<String> urlPatterns = Lists.newArrayList();
//        urlPatterns.add("/api/");
//
//        registrationBean.addUrlPatterns(urlPatterns.toArray(new String[urlPatterns.size()]));
//        return registrationBean;
//    }


}
